package  edu.psu.collegerecommendationhelper.coreservlets;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

import edu.psu.collegerecommendationhelper.database.GenericDatabase;
import edu.psu.collegerecommendationhelper.database.MySQLDatabase;
import edu.psu.collegerecommendationhelper.model.AccountInfo;
import edu.psu.collegerecommendationhelper.model.UserBean;



@ManagedBean(name="fbLoginBean")
public class FBLoginController {
   @ManagedProperty(value="#{userBean}")
   private UserBean user;

   private String fb_id;
   private String fb_firstname;
   private String fb_lastname;
   private String fb_email;


   //Getters and Setters
   public UserBean getUser() {
      return user;
   }
   public void setUser(UserBean user) {
      this.user = user;
   }

   public String getFb_id() {
      return fb_id;
   }
   public void setFb_id(String fb_id) {
      this.fb_id = fb_id;
   }

   public String getFb_firstname() {
      return fb_firstname;
   }
   public void setFb_firstname(String fb_firstname) {
      this.fb_firstname = fb_firstname;
   }

   public String getFb_lastname() {
      return fb_lastname;
   }
   public void setFb_lastname(String fb_lastname) {
      this.fb_lastname = fb_lastname;
   }

   public String getFb_email() {
      return fb_email;
   }
   public void setFb_email(String fb_email) {
      this.fb_email = fb_email;
   }


////////////////////////////////////////////////////////////////////////

   public String populateUser() throws ClassNotFoundException {
      MySQLDatabase mysqlDB = new MySQLDatabase();
      GenericDatabase genDB;
      genDB = mysqlDB;

      AccountInfo fbInfo= new AccountInfo();
      UserBean temp_user = new UserBean();

      fbInfo.setFbID(fb_id);
      fbInfo.setFirstname(fb_firstname);
      fbInfo.setLastname(fb_lastname);
      fbInfo.setEmail(fb_email);

      temp_user = genDB.retrieveUser(fbInfo);

      user.setUser_id(temp_user.getUser_id());
      user.setAccountInfo(temp_user.getAccountInfo());
      user.setDemographicInfo(temp_user.getDemographicInfo());
      user.setEducationInfo(temp_user.getEducationInfo());
      user.setPreferenceInfo(temp_user.getPreferenceInfo());
      user.setResultList(temp_user.getResultList());

      return("MainPage");
	          
   }

}